home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / PGM_TOOL / PREVIEW / README.TXT < prev    next >
Text File  |  1995-11-12  |  8KB  |  182 lines

  1.  
  2. Author: Brad Tharalson, CIS 72030,3045
  3.  
  4. After unpacking:   Installed Directory-
  5.                      Print Preview sample project.
  6.                         Samples Sub-Directory-
  7.                           Delphi code used to create samples.
  8.                         Clp2Dlfi Sub-Directory-
  9.                           Project for converting xBase to Delphi code.
  10.                         OrgFiles Sub-Directory-
  11.                           Files as I use them, no changes
  12.  
  13. PrnInit.txt  Contains list of printers and Queues that are available.
  14.              Loaded during StartLinePrinter().  If your printer is not on
  15.              the list,  you will need to add it to the file, just add a
  16.              new entry similar to the existing items.  Ignore the Queue
  17.              stuff for now.
  18.  
  19. In the installed directory is the project file (PrnPrev.dpr) with samples
  20. of using the wPreview unit.  Open the project, ignore the message, if any,
  21. that says: Error Reading Symbol File.  Build and Run the program.
  22.  
  23. It starts with a Select Printer form, if your current printer is not shown
  24. then please select it.  Make sure the "Preview Reports Before Printing"
  25. checkbox is selected.
  26.  
  27. Under the "Preview Samples" menu choice, select any choice, these consist
  28. of several prepared command list files that are then "Played Back", more
  29. later. When on the Preview form, you can use the popup menu attached to the
  30. right button to select the choices at the top of the Preview form if they
  31. should scroll off the forms canvas.
  32.  
  33. For the "View Blue Print" selection, there are two bitmaps involved.  The full
  34. size image is 2200x1700 (470k), the "Select" image is only 613x337.  The
  35. "Select" image appears first, click anywhere on this image and wait
  36. a few seconds, the appropriate area on the full image will come into view.
  37. You can then use "Up","Down", etc., buttons to move around the image or if
  38. you click on the full image the "Select" image reappears and you can select
  39. a new area to view, in essence, hop back and forth.
  40.  
  41. Before you try the "Print Blue Print" test, make sure your printer resolution
  42. is less than or equal to 300 DPI.  I've had problems with higher resolutions.
  43.  
  44. wPreview Unit Concept
  45. ---------------------
  46.  
  47. I tried to find a unit I could use to give my software the same "Print With
  48. Preview" capability found in commercial packages.  Unfortunately I couldn't
  49. find something to fit my needs.
  50.  
  51. Printing is very easy in Delphi using their supplied Printers unit.  For
  52. years my end-users have been able to view plain text reports on the screen
  53. before printing.  First, I wrote the routine to send each canvas page to
  54. the screen or printer as they have chosen.  Then, they wanted to be
  55. able to hop around among different pages and print as needed.
  56.  
  57. So I decided that I would capture all of parameters passed into the routines
  58. I already use for printing. Search for AddCommand() lines in wPreview.pas.
  59. If they wanted it to go directly to the printer the parameters are not saved,
  60. and the commands are immediately processed.  Otherwise the commands are saved
  61. in a TStringList object so the can be previewed when done formatting.
  62.  
  63. Each group of routines for a page are kept separate in their own TStringList
  64. object, at any time a single page or all pages can be passed to the
  65. PlayBackPage routine and it will clear the current drawing canvas and
  66. process the commands in the TStringList in the same order they were created.
  67.  
  68. These TStringList objects can also be saved to a file for later playback,
  69. see the SaveCommands and LoadCommands routines.  Most of the sample
  70. choices are just command files that are being played back, these were
  71. generated using our Job Costing system. The saving occured in the PlayBackPage
  72. routine, search for SaveCommands() in PlayBackPage, you'll see where I
  73. commented it out.
  74.  
  75. I have included the Delphi code used to generate the Command files that are
  76. played back on the sample menu. Search for "StartDoc" in the Delphi files below:
  77.  
  78. Command File         Menu Choice
  79. ------------         -----------
  80. DemoRout.txt      Preview Routing Card,  see Samples/RoutCard.pas
  81. DemoJob.txt       Preview Job Cost,      see Samples/JBdet.pas
  82. DemoInfo.txt      Preview Job Due/Ship,  see Samples/JCcommon.pas
  83.  
  84.  
  85. Using The wPreview Unit
  86. -----------------------
  87.  
  88.   Use "Select Printer" menu choice under "File" menu to set the print
  89.   destination and whether to preview reports before printing.
  90.  
  91.   1.  Create "Lpr" object, use its methods to create format your print file.
  92.   2.  "TPreview" form (Minimized) is created whether you want Report
  93.       Preview or not.  This is nice because you will see icons showing
  94.       all the reports you are currently formatting.
  95.   3.  When you end your series of print commands with StopDoc(), one of two
  96.       things will happen:
  97.         a. Preview On: TPreview form is maximized, first page appears.
  98.                        TPreview form stays open until you close it.
  99.  
  100.            Lpr --> Creates Commands List --> TPreview form created -->
  101.              Lpr (destroyed) --> TPreview (standalone) uses its own Lpr
  102.                                  object to view and/or print pages as needed.
  103.  
  104.         b. Preview Off: TPreview form is minimized until printing is done
  105.                         and then closed.
  106.  
  107.            Lpr --> Commands Direct To Printer --> Lpr (destroyed)
  108.  
  109.  
  110. Code Sample:   Print Customer Names List (simplified)
  111. -----------
  112.  
  113.     procedure CustLIst;
  114.     var lpp:Lpr;  { Lpr is in unit wPreview.pas }
  115.         tdb:oDB:  { from DBserver.pas unit in Clp2Dlfi directory }
  116.     begin
  117.       lpp:=Lpr.create;
  118.       tdb:=nil;
  119.       dbUse(tdb,'cust');  { open Cust.dbf }
  120.       with lpp do begin
  121.         SetDestination;
  122.         { Tell system, report is designed for 8 1/2 by 11 paper. If you had
  123.           used "for14x11" instead, it would automatically condense print
  124.           if a user selected a letter size paper printer, or full size print
  125.           on a wide carriage printer, see PrnInit.txt file }
  126.         StartDoc(for8x11,'Customer List');
  127.         while not tdb.eof do begin
  128.           { have to use "lpp.writeln" because WriteLn is built-in to Delphi,
  129.             and it takes precedence if no object qualifier }
  130.           lpp.writeln(tdb.s('name')+'  ('+tdb.s('cust_no')+')');
  131.         end;
  132.         StopDoc;
  133.       end;
  134.       dbClose(tdb);
  135.       lpp.free;
  136.     end;
  137.  
  138. SetDestination should only be called once just before starting a series
  139. of StartDoc-StopDoc sequences.  You can use the wPreview.pas unit to
  140. format several reports at the same time, some you may have wanted
  141. to preview when done, others you may be sending to one or more different
  142. printers.
  143.  
  144. Note: There is no BTPrint.pas file for the BTPrint.dcu file.  I was having
  145.       some problems with the GetCanvas routine in Printers.pas in the VCL,
  146.       I suspect it is somewhere in Win95.  So I moved the FCanvas declaration
  147.       to the public section and set it to Nil in the TPrinterCanvas.Create
  148.       routine.  I don't think I can give you this changed code because
  149.       it's Borland's.  But I think I can give you the compiled unit which
  150.       is all that is really necessary.  If you accidently remove the
  151.       BTPrint.dcu unit, you can copy BTPrint.ucd to BTPrint.dcu. Or you
  152.       can substitute the unit Printers unit for the BTPrint unit and correct
  153.       "fcanvas" to canvas in a couple of places in wPreview.pas (the compiler
  154.       would kick these out).
  155.  
  156. These are some packages I use in developing in case I didn't get all
  157. references to these removed and some compile errors occur, just delete
  158. any references:   All are available from Programmer's SuperShop and elsewhere.
  159.  
  160. wPreview.pas: Used in Capture() and EndCap() routines
  161.  
  162.   Apiary Netware Developer Suite For Delphi
  163.   Apiary, Inc.
  164.  
  165. wPreview.pas: TrueBar Unit, TBarCode control;
  166.  
  167.   TrueBar II (Bar Code Library)
  168.   American Barcode Systems, Inc.
  169.  
  170. DBserver.pas: Used extensively for database management .
  171.               Not needed for printing.
  172.  
  173.   ROCKET DataBase Manager
  174.   Successware, Inc.
  175.  
  176.  
  177.  
  178. Hope the samples and the wPreview.pas routines can save you some time.
  179.  
  180. Brad Tharalson
  181. 72030,3045
  182.